package com.example.star_wars_obiwan;

import android.annotation.TargetApi;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

@TargetApi(11)
public class IMHelper extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		Log.i("tag_MainActivity", "?>>:obiwan help!");
		Toast.makeText(context, "?>>:obiwan help!", Toast.LENGTH_LONG).show();

		NotificationManager notificationManager = (NotificationManager) context.getSystemService(Service.NOTIFICATION_SERVICE);
		Intent activityIntent = new Intent(context, MainActivity.class);
		PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, activityIntent, PendingIntent.FLAG_UPDATE_CURRENT);

//		Notification notification = new Notification();
//		notification.contentIntent = pendingIntent;
//		notification.icon = R.drawable.ic_launcher;
//		notification.tickerText = "obiwan help!";
//		notification.when = System.currentTimeMillis();
//		notification.flags |= Notification.FLAG_AUTO_CANCEL;
//		notification.setLatestEventInfo(context, "yoda help!", "yoda help!", pendingIntent);

		Notification notification = new Notification.Builder(context)//
				.setContentTitle("obiwan help! new")//
				.setSmallIcon(R.drawable.ic_launcher)//
				.setContentText("obiwan help! new")//
				.setWhen(System.currentTimeMillis())//
				.setContentIntent(pendingIntent)//
				.setAutoCancel(true)//
				.getNotification();

		notificationManager.notify(101, notification);

	}
}
